package com.telecom.cms.actions;

import java.io.IOException;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;

import com.telecom.cms.dao.*;
import com.telecom.cms.dto.*;

/**
 * @author yueyingnishang
 * 
 */
public class MetersToJSP extends BodyTagSupport {

	private String precision;

	public String getPrecision() {
		return this.precision;
	}

	public void setPrecision(String precision) {
		this.precision = precision;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.jsp.tagext.BodyTagSupport#doAfterBody()
	 */
	public int doAfterBody() throws JspException {
		// TODO Auto-generated method stub
		Connection con = GetConnect.getCsConnection();
		List list = new ArrayList();
		SEG_BOOKMARK_DEFDAO dao = new SEG_BOOKMARK_DEFDAO(con);
		// System.out.println(precision);
		if (1 == Integer.parseInt(precision)) {

			list = dao.findById(1);
		} else {
			list = dao.findById(2);
		}
		BodyContent body = this.getBodyContent();
		StringBuffer st = new StringBuffer();
		st
				.append("<table width='100%' border='0' cellspacing='0' cellpadding='0'>                                                                                          ");

		st.append("  <tr>");
		for (int i = 0; i < list.size(); i++) {
			SEG_BOOKMARK_DEFDTO dto = (SEG_BOOKMARK_DEFDTO) list.get(i);
			st
					.append("    <td height='30' background='images/Jrcj_Middle_Line.gif'>&nbsp;&nbsp;&nbsp; <img src='images/b_dot_2.gif' width='9' height='9'>&nbsp;&nbsp;&nbsp;<a id="
							+ dto.getBOOKMARK_ID()
							+ " href = 'uptest.do?bookmarkid="
							+ dto.getBOOKMARK_ID() + "' target='mainFrame' > "
							+ dto.getBOOKMARK_NAME() + "</a></td>  ");
		}
		st.append("  <tr>");
		st
				.append("</table>																																																																									");

		try {
			body.getEnclosingWriter().println(st.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// System.out.println(st.toString());
		return EVAL_PAGE;
		// return st.toString();
	}
}
